package com.poetize.plus.entity.dto;

import com.poetize.plus.entity.po.Family;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Null;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;

/**
 * @Author zuosy
 * @Date 2024/5/13 20:44
 **/
public record FamilyDTO(
        @Schema(description = "ID")
        @Null(message = "ID必须为空", groups = {Insert.class})
        @NotNull(message = "ID不能为空", groups = {Update.class})
        Long id,

        @Schema(description = "男生头像")
        @NotNull(message = "男生头像不能为空", groups = {Insert.class, Update.class})
        String manCover,

        @Schema(description = "女生头像")
        @NotNull(message = "女生头像不能为空", groups = {Insert.class, Update.class})
        String womanCover,

        @Schema(description = "男生名称")
        @NotNull(message = "男生名称不能为空", groups = {Insert.class, Update.class})
        String manName,

        @Schema(description = "女生头像")
        @NotNull(message = "女生头像不能为空", groups = {Insert.class, Update.class})
        String womanName,

        @Schema(description = "相遇时间")
        @NotNull(message = "相遇时间不能为空", groups = {Insert.class, Update.class})
        LocalDate startDate,

        @Schema(description = "是否启用")
        @NotNull(message = "是否启用不能为空", groups = {Insert.class, Update.class})
        Boolean status
) {

    /**
     * DTO转实体类
     *
     * @param familyDTO
     * @return
     */
    public static Family convertDTO(FamilyDTO familyDTO) {
        return new Family(familyDTO.id, familyDTO.manCover, familyDTO.womanCover, familyDTO.manName, familyDTO.womanName, familyDTO.startDate, familyDTO.status);
    }
}
